﻿<%@ Page Title="POSSystem | Products" Language="C#" MasterPageFile="~/Application.Master" AutoEventWireup="true"
    CodeBehind="Product.aspx.cs" Inherits="WebUI.Product" Theme="POSSystem" %>

<%@ Register Src="~/Controls/SysControls/PageHeader.ascx" TagPrefix="uc" TagName="PageHeader" %>
<%@ Register Src="~/Controls/POSControls/ProductListCtrl.ascx" TagName="ProductList"
    TagPrefix="uc" %>
<%@ Register Src="~/Controls/SysControls/GridFilterPaging.ascx" TagName="GridFilterPaging"
    TagPrefix="uc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ApplicationHeadHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ApplicationContentHolder" runat="server">
    <script type="text/javascript">
        function treeCategories_selectedIndexChanged() {
            var treeCategories = window["<%=tvCategory.ClientID%>" + "_Data"];
            
            if (treeCategories.selectedNodeID.value != "") {
                var selectedNode = document.getElementById(treeCategories.selectedNodeID.value);

                var value = selectedNode.href.substring(selectedNode.href.indexOf(",") + 3, selectedNode.href.length - 2);

                var hidSelectedNodePath = document.getElementById("<%=hidSelectedNodePath.ClientID%>");
                hidSelectedNodePath.value = value;
                
                var hidSelectedNodeValue = document.getElementById("<%=hidSelectedNodeValue.ClientID%>");
                var nodeId = value.substr(value.lastIndexOf("\\") + 1);
                if(nodeId != hidSelectedNodeValue.value){
                    hidSelectedNodeValue.value = nodeId;
                    document.getElementById("<%=btnLoadByCat.ClientID %>").click();
                }
            }
            return false;
        }
        
        function onAddCategory(){
            var hidSelectedNodeValue = document.getElementById("<%=hidSelectedNodeValue.ClientID%>");
            if (hidSelectedNodeValue.value == '') {
                alert('Please select a category node!');
                return false;
            }
            var returnValue = window.showModalDialog('<%=GetCategoryEditPageLink() %>' + '&mode=new&id=' + hidSelectedNodeValue.value, '', 'dialogWidth=500px;dialogHeight=200px;resizable=no;help=no;unadorned=yes;');

            return returnValue > 0;
        }

        function onEditCategory() {
            var hidSelectedNodeValue = document.getElementById("<%=hidSelectedNodeValue.ClientID%>");
            if (hidSelectedNodeValue.value == '') {
                alert('Please select a category node!');
                return false;
            }
            if (hidSelectedNodeValue.value == '0') {
                alert('Can not edit the root node. Please select another one!');
                return false;
            }
            
            var returnValue = window.showModalDialog('<%=GetCategoryEditPageLink() %>' + '&mode=edit&id=' + hidSelectedNodeValue.value,
                '', 'dialogWidth=500px;dialogHeight=200px;resizable=no;help=no;unadorned=yes;');

            return returnValue > 0;
        }

        function onRemoveCategory() {
            var hidSelectedNodeValue = document.getElementById("<%=hidSelectedNodeValue.ClientID%>");
            if (hidSelectedNodeValue.value == '') {
                alert('Please select a category node!');
                return false;
            }
            if (hidSelectedNodeValue.value == '0') {
                alert('Can not delete the root node. Please select another one!');
                return false;
            }

            return confirm("Delete a category will affect all related products. Do you want to continue?");
        }

        function onAddProduct() {
            var id = getSelectedItemID<%=lstProducts.ClientID %>();
            var returnValue = window.showModalDialog('<%=GetProductEditPageLink() %>' + '&mode=new', '', 'dialogWidth=800px;dialogHeight=600px;resizable=no;help=no;unadorned=yes;');

            return returnValue > 0;
        }

        function onEditProduct() {
            var id = getSelectedItemID<%=lstProducts.ClientID %>();
            if(id == null){
                alert("No item was selected!");
                return false;
            }
            var returnValue = window.showModalDialog('<%=GetProductEditPageLink() %>' + '&mode=edit&id=' + id, '', 'dialogWidth=800px;dialogHeight=600px;resizable=no;help=no;unadorned=yes;');
            return returnValue > 0;
        }

        function onRemoveProduct() {
            var id = HasCheckedItems<%=lstProducts.ClientID %>();
            if(id == false){
                alert("No item was selected!");
                return false;
            }
            
            return confirm("This action will delete all checked items. Do you want to continue?");
        }
        
        function showPrintDlg(key){
            var returnValue = window.showModalDialog(key, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');
        }

    </script>

    <uc:PageHeader ID="pageHeader" Text="Products" ImageURL="~/Images/Product.png" runat="server" />
    <table width="100%">
        <tr>
            <td style="width: 25%; text-align: left; vertical-align: top">
                <asp:Panel ID="panelCategory" runat="server" class="primaryPanel">
                    <div class="titleBar">
                        <asp:Label ID="lblTitle1" runat="server" CssClass="titleContent">Categories</asp:Label>
                    </div>
                    <asp:UpdatePanel runat="server" ID="updateCategory" UpdateMode="Conditional">
                        <ContentTemplate>
                            <div class="primaryFrameNoBorder">
                                <div>
                                    <table class="toolbar" width="100%">
                                        <tr>
                                            <td>
                                                <asp:LinkButton class="tbbutton" ID="btnAddCategory" runat="server" OnClientClick="return onAddCategory();"
                                                    OnClick="btnAddCategory_OnClick">
                                                    <img src="Images/AddRecord.gif" /><asp:Label ID="label1" runat="server" Text="Add"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnEditCategory" runat="server" OnClientClick=" return onEditCategory();"
                                                    OnClick="btnAddCategory_OnClick">
                                                    <img src="Images/Edit.gif" /><asp:Label ID="label2" runat="server" Text="Edit"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnRemoveCategory" runat="server" OnClientClick="return onRemoveCategory();"
                                                    OnClick="btnRemoveCategory_OnClick">
                                                    <img src="Images/Delete.gif" /><asp:Label ID="label3" runat="server" Text="Delete"></asp:Label>
                                                </asp:LinkButton>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <asp:TreeView ID="tvCategory" runat="server" ShowLines="true" onclick="return treeCategories_selectedIndexChanged();">
                                    <SelectedNodeStyle CssClass="selectedNode" />
                                    <NodeStyle CssClass="labelMessage" />
                                </asp:TreeView>
                            </div>
                            <div style="display: none">
                                <asp:HiddenField ID="hidSelectedNodeValue" runat="server" />
                                <asp:HiddenField ID="hidSelectedNodePath" runat="server" />
                            </div>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </asp:Panel>
            </td>
            <td style="width: 75%; text-align: right; vertical-align: top">
                <asp:Panel ID="panelProduct" runat="server" class="primaryPanel" DefaultButton="btnSearchProduct">
                    <div class="titleBar">
                        <asp:Label ID="Label4" runat="server" CssClass="titleContent">Product List</asp:Label>
                    </div>
                    <asp:UpdatePanel runat="server" ID="updateProduct" UpdateMode="Conditional">
                        <Triggers>
                            <asp:PostBackTrigger ControlID="btnExcel" />
                        </Triggers>
                        <ContentTemplate>
                            <div class="primaryFrameNoBorder">
                                <div>
                                    <table width="100%" class="toolbar">
                                        <tr>
                                            <td style='vertical-align: middle'>
                                                <asp:LinkButton class="tbbutton" ID="btnAddProd" runat="server" OnClientClick="return onAddProduct();"
                                                    OnClick="btnAddProduct_OnClick">
                                                    <img src="Images/AddRecord.gif" /><asp:Label ID="label5" runat="server" Text="Add"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnEditProd" runat="server" OnClientClick=" return onEditProduct();"
                                                    OnClick="btnAddProduct_OnClick">
                                                    <img src="Images/Edit.gif" /><asp:Label ID="label6" runat="server" Text="Edit"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnDeleteProd" runat="server" OnClientClick="return onRemoveProduct();"
                                                    OnClick="btnRemoveProduct_OnClick">
                                                    <img src="Images/Delete.gif" /><asp:Label ID="label7" runat="server" Text="Delete"></asp:Label>
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:LinkButton class="tbbutton" ID="btnPrintProduct" runat="server" OnClick="btnPrintProduct_OnClick">
                                                    <img src="Images/print.gif" /><asp:Label ID="label8" runat="server" Text="Print"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnExcel" runat="server" OnClick="btnExcel_OnClick">
                                                    <img src="Images/excel.gif" /><asp:Label ID="label9" runat="server" Text="Export"></asp:Label>
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:TextBox ID="txtSearchProduct"  Width="80px" runat="server"></asp:TextBox>
                                                <asp:LinkButton class="tbbutton" ID="btnSearchProduct" runat="server" OnClick="btnSearchProduct_OnClick">
                                                    <img src="Images/search.png" />
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:LinkButton class="tbbutton" ID="btnReload" runat="server" OnClick="btnReload_OnClick">
                                                    <img src="Images/reload.png" /><asp:Label ID="label11" runat="server" Text="Reload"></asp:Label>
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                            </td>
                                            <td style='vertical-align: middle; text-align: right'>
                                                <asp:Label ID="label12" runat="server" Text="Filter:"></asp:Label>
                                                <asp:DropDownList ID="ddlFilter" runat="server" class='searchTextBox' AutoPostBack="true" Width="80px"
                                                    OnSelectedIndexChanged="ddlFilter_OnSelectedIndexChanged">
                                                    <asp:ListItem Text="-- All --" Value="0"></asp:ListItem>
                                                    <asp:ListItem Text="New Arrival" Value="1"></asp:ListItem>
                                                    <asp:ListItem Text="Daily Special" Value="2"></asp:ListItem>
                                                    <asp:ListItem Text="Home Visivle" Value="3"></asp:ListItem>
                                                    <asp:ListItem Text="Dealer Only" Value="4"></asp:ListItem>
                                                </asp:DropDownList>
                                                <asp:Label ID="label10" runat="server" Text="Brand:"></asp:Label>
                                                <asp:DropDownList ID="ddlBrand" runat="server" class='searchTextBox' AutoPostBack="true"  Width="100px"
                                                    OnSelectedIndexChanged="ddlBrand_OnSelectedIndexChanged">
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <asp:UpdatePanel ID="updateByCat" runat="server" UpdateMode="Conditional">
                                    <ContentTemplate>
                                        <uc:ProductList OnProductNameClick="lstProducts_OnProductNameClick" AllowViewDetails="true" ID="lstProducts" runat="server" Width="100%" AllowPaging="true" AllowSorting="true"
                                            AllowSelecting="true" SaveOnCommit="false" />
                                        <asp:Button ID="btnLoadByCat" runat="server" OnClick="btnLoadByCat_OnClick" Style="display: none" />
                                        <div style="height: 10px">
                                            &nbsp;</div>
                                        <uc:GridFilterPaging ID="gridFilterPaging" runat="server" FilteredField="ProductName"
                                            OnNeedListControl="gridFilterPaging_OnNeedListControl" />
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </div>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </asp:Panel>
            </td>
        </tr>
    </table>
</asp:Content>
